﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Client;

namespace SimpleDelphiExpert
{
    class TfsFileHistoryProvider: FileHistoryProvider
    {
        private TfsTeamProjectCollection Tfs;
        private VersionControlServer vcs;
        private const string providerIdent = "SimpleDelphiExpert.TfsFileHistoryProvider";
        private const string providerName = "DSE TfsFileHistoryProvider";

        protected override bool DoConnect()
        {
            Tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(TfsConnection.Default.TfsCollectionUri);
            vcs = Tfs.GetService<VersionControlServer>();
            return true;
        }

        protected override Borland.Studio.ToolsAPI.IOTAFileHistory DoGetFileHistory(string AFileName)
        {
            /*IEnumerable history = vcs
                .QueryHistory(AFileName, VersionSpec.Latest, 0, RecursionType.Full, null, null, null, Int32.MaxValue, true, false);
            return new TfsFileHistory(history);*/
            QueryHistoryParameters parameters = new QueryHistoryParameters(AFileName, RecursionType.Full);
            parameters.IncludeChanges = true;
            IEnumerable<Changeset> history = vcs.QueryHistory(parameters);
            return new TfsFileHistory(history);
        }

        public override string Ident
        {
            get { return providerIdent; }
        }

        public override string Name
        {
            get { return providerName; }
        }
    }
}
